/**
 * 
 */
package com.totobox.apps.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.totobox.apps.Const;
import com.totobox.apps.R;

/**
 * @author ytslove
 * 
 */
public class NoticeCustomDialog extends Dialog {

	private ImageView btn_close;
	private ImageButton btn_notice_prev;
	private ImageButton btn_notice_next;
	
	private int adTotal = 0;
	private int currPos = 0;
	private List<String> adList = new ArrayList<String>();

	public List<Map<String,String>> noticeList;
	
	public NoticeCustomDialog(Context context) {
		super(context);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		this.setContentView(R.layout.dialog_notice_view);
		
		noticeList = TotoIFData.NoticeList("0","0","4","10","android");
		
		if(noticeList != null && !noticeList.isEmpty()){
			 
			this.adTotal = noticeList.size();
			for(int i = 0 ; i < adTotal ; i++){
				adList.add(noticeList.get(i).get("vcContent"));
			}
			
		}
		else{
			adList.add("현재 홍보 문구가 없습니다.");
		}
		
		
		//this.adTotal = adList.size();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		final TextView contents = (TextView)findViewById(R.id.notice_msg);
		contents.setText(adList.get(adTotal-1));
		
		btn_close = (ImageView)findViewById(R.id.btn_close);
		
		btn_notice_prev = (ImageButton)findViewById(R.id.btn_notice_prev);
		btn_notice_next = (ImageButton)findViewById(R.id.btn_notice_next);
		
		//현재 홍보 문구는 최신으로...
		currPos = adTotal-1;
		
		btn_notice_prev.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(currPos > 0){
					currPos--;
					contents.setText(adList.get(currPos));
				}
			}
		});
		
		btn_notice_next.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(currPos < (adTotal-1)){
					currPos++;
					contents.setText(adList.get(currPos));
					
				}
			}
		});
		
		btn_close.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Const.isAlertView = true;
				dismiss();
			}
		});
	}

}
